package jdbc;

import java.sql.*;

public class JDBCDemo1 {
    /*
    * */
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        /*导入jar包*/
        /*1.注册驱动*/
        Class.forName("com.mysql.cj.jdbc.Driver");
        /*2.创建链接*/
        Connection connection = DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root"

        );
        System.out.println("与数据库连接成功");
        /*3.获取执行者对象*/
        Statement statement = connection.createStatement();

        String sql ="CREATE TABLE userinfo(\n" +
                "    id INT PRIMARY KEY AUTO_INCREMENT,\n" +
                "    username VARCHAR(32),\n" +
                "    password VARCHAR(32),\n" +
                "    nickname VARCHAR(32),\n" +
                "    age INT(3)\n" +
                ")";
//       /*4.执行SQL语句*/
        statement.execute(sql);
        System.out.println("建表成功");
        /*5.关闭连接*/
        connection.close();
    }


}
